import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Health Bar for Dr. Wily and Chris Hansen
 */
public class BossHealth  extends Actor
{
    retroWorld theWorld;
    private int hitPoints;
    
    private GreenfootImage[] healthBar;
    
    /** Constructor for BossHealth, passing the number of hit points as a parameter
     * 
     */
    public BossHealth(int hp)
    {
        if (hp > 10 || hp == 0)
            hitPoints = 10;
        else
            hitPoints = hp;
        
        healthBar = new GreenfootImage[11];
        for (int i = 0; i < hitPoints; i++)
        {
            healthBar[i] = new GreenfootImage("wilyHealth" + i + ".png");
        }
        
        setImage(healthBar[hitPoints]);
    }
    
    public void addedToWorld(World world)
    {
        theWorld = (retroWorld)world;
    }
    
    /** Take Damage from attacks and decrement and set Image for the health bar appropriately
     * 
     */
    public void takeDamage()
    {        
        hitPoints--;
        setImage(healthBar[hitPoints]);
        
        if (hitPoints == 0)
            theWorld.removeObject(this);
    }
}
